#include "delay.h"
#include "jtag.h"
#include "relay.h"
#include "input-button.h"
#include "modbus_rtu_slave.h"
#include "user_operate.h"
#include "lcm.h"
#include "drv_common.h"
#include "menu.h"
#include "stm32f10x.h"
#include "rtc.h"
#include "tasks.h"

int main(void)
{
    struct task tsk[] = {
        {
            .target_time = {2021, 10, -1, 0, -1, -1, 0},
            .active = RELAY_ACT_ON,
            .is_enable = 1,
            .type = ABSOLUTE,
        },{
            .target_time = {2021, 10, -1, 0, -1, -1, 1},
            .active = RELAY_ACT_OFF,
            .is_enable = 1,
            .type = ABSOLUTE,
        },{
            .target_time = {2021, 9, 29, 0, 9, -1, 0},
            .active = RELAY_ACT_ON,
            .is_enable = 1,
            .type = ABSOLUTE,
        },{
            .target_time = {2021, 9, 29, 0, 9, 0, 0},
            .active = RELAY_ACT_OFF,
            .is_enable = 1,
            .type = COUNTDOWN,
        },{
            .target_time = {2021, 9, 29, 0, 9, 0, 0},
            .active = RELAY_ACT_OFF,
            .is_enable = 1,
            .type = LOOP,
        },{
            .target_time = {2021, 9, 29, 0, 9, 1, 0},
            .active = RELAY_ACT_ON,
            .is_enable = 1,
            .type = LOOP,
        },
    };
    
	delay_init(72);
    jtag_config(swd_only);
    rtc_init();
    tasks_init(2);
    relay_init();
    input_button_init();
    lcm_init();    
    
//    task_insert(tsk, 0);
//    task_insert(tsk + 1, 0);
//    task_insert(tsk + 2, 0);
//    task_insert(tsk + 3, 0);
//    task_insert(tsk + 4, 0);
//    task_insert(tsk + 5, 0);
    
    menu_init();
        
    while (1) {
        menu_task();
        delay_ms(100);
    }

//	return 0;
}
